#try to find Qtilities libs and include

#variables set:
#QTILITIES_FOUND
#QTILITIES_INCLUDE_DIRS
#QTILITIES_LIBRARIES

SET(QTILITIES_FOUND FALSE)

SET(QTILITIES_INCLUDE_DIRS)
SET(QTILITIES_LIBRARIES)

FIND_PATH(QTILITIES_INCLUDE_DIR QtilitiesCore/QtilitiesCore
	${QTILITIES_DIR}/include
	$ENV{QTILITIES_DIR}/include
	NO_DEFAULT_PATH
)

MACRO(QTILITIES_FIND_COMPONENTS COMPONENT COMPONENT_NAME)
	SET(${COMPONENT}_FOUNG FALSE)
	
	FIND_PATH(${COMPONENT}_INCLUDE_DIR ${COMPONENT_NAME}
	${QTILITIES_DIR}/include/${COMPONENT_NAME}
	$ENV{QTILITIES_DIR}/include/${COMPONENT_NAME}
	${QTILITIES_INCLUDE_DIR}/${COMPONENT_NAME}
	NO_DEFAULT_PATH
	)
	

	FIND_LIBRARY("${COMPONENT}_DEBUG"
	NAMES "${COMPONENT_NAME}${CMAKE_DEBUG_POSTFIX}"
	PATHS
	$ENV{QTILITIES_DIR}/bin
	$ENV{QTILITIES_DIR}/bin/debug
	$ENV{QTILITIES_DIR}/lib
	$ENV{QTILITIES_DIR}/lib/debug
	)
	
	FIND_LIBRARY("${COMPONENT}_RELEASE"
	NAMES "${COMPONENT_NAME}"
	PATHS
	$ENV{QTILITIES_DIR}/lib
	$ENV{QTILITIES_DIR}/lib/release
	$ENV{QTILITIES_DIR}/bin
	$ENV{QTILITIES_DIR}/bin/release
	)

	IF(NOT ${COMPONENT}_DEBUG)
		IF(${COMPONENT}_RELEASE)
			SET(${COMPONENT}_DEBUG ${COMPONENT}_RELEASE)
			SET(${COMPONENT}_FOUNG TRUE)
		ENDIF()
	ENDIF()
	
	IF(${COMPONENT}_DEBUG AND ${COMPONENT}_RELEASE AND ${COMPONENT}_INCLUDE_DIR)
		SET(${COMPONENT}_FOUNG TRUE)
		LIST(APPEND QTILITIES_INCLUDE_DIRS ${${COMPONENT}_INCLUDE_DIR})
		SET(QTILITIES_LIBRARIES 
			${QTILITIES_LIBRARIES}
			optimized ${${COMPONENT}_RELEASE} debug ${${COMPONENT}_DEBUG}
			)
	ENDIF()
	
	IF(${COMPONENT}_FOUNG)
		SET(QTILITIES_FOUND TRUE)
	ENDIF()

ENDMACRO(QTILITIES_FIND_COMPONENTS COMPONENT COMPONENT_NAME)

QTILITIES_FIND_COMPONENTS(QTILITIES_CORE QtilitiesCore)
QTILITIES_FIND_COMPONENTS(QTILITIES_COREGUI QtilitiesCoreGui)
QTILITIES_FIND_COMPONENTS(QTILITIES_LOGGING QtilitiesLogging)
QTILITIES_FIND_COMPONENTS(QTILITIES_PROJECTMANAGEMENT QtilitiesProjectManagement)
QTILITIES_FIND_COMPONENTS(QTILITIES_TESTING QtilitiesTesting)

